package com.niknik.woody.guice;

import com.google.appengine.api.channel.ChannelService;
import com.google.appengine.api.channel.ChannelServiceFactory;
import com.google.inject.AbstractModule;
import com.google.inject.Singleton;
import com.google.inject.TypeLiteral;
import com.google.inject.name.Names;
import com.niknik.woody.core.ServerToClientTransmitter;
import com.niknik.woody.core.room.Room;
import com.niknik.woody.core.room.RoomRegistry;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class CoreModule
    extends AbstractModule {

  @Override
  protected void configure() {
    bind(RoomRegistry.class).in(Singleton.class);
    bind(ServerToClientTransmitter.class).in(Singleton.class);
    bind(ChannelService.class).toInstance(ChannelServiceFactory.getChannelService());

    bind(new TypeLiteral<Map<Long, Room>>() {
    }).toInstance(new ConcurrentHashMap<Long, Room>());

    bind(Long.class).annotatedWith(Names.named(Room.MAX_ROOM_IDLE_MILLIS)).toInstance(300000L);
  }
}
